package com.scsj.supermarket.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.example.xlhratingbar_lib.XLHRatingBar;
import com.scsj.supermarket.R;
import com.scsj.supermarket.bean.SelectAppRankBean;
import com.scsj.supermarket.event.FirstEvent;
import com.scsj.supermarket.utils.RxBus;
import com.scsj.supermarket.utils.Tool;

import java.util.List;

/**
 * 我的评论
 */

public class MineCommentAdapter  extends BaseQuickAdapter<SelectAppRankBean.DataBean.ListBean,BaseViewHolder> {

    //加载图片评论布局
    private LinearLayout reputationImgLayout;
    private List<SelectAppRankBean.DataBean.ListBean> data;
    private Context context;
    public MineCommentAdapter(List data, Context context) {
        super(R.layout.item_comment_layout,data);

        this.data=data;
        this.context= context;
    }

    @Override
    protected void convert(BaseViewHolder helper, SelectAppRankBean.DataBean.ListBean item) {

        reputationImgLayout= helper.getView(R.id.goods_detail_add_view_tv);

        Glide.with(context).load(item.getResourceInfoUser()).into((ImageView) helper.getView(R.id.goods_detail_user_img_tv));
        helper.setText(R.id.nickname_tv,item.getNickname());
        helper.setText(R.id.goods_detail_time_tv,item.getGoodsEvaluationDetails().getCreateTime());
        ((XLHRatingBar)helper.getView(R.id.ratingBar)).setCountNum(item.getGoodsEvaluationDetails().getGevalScoresGoods());
        helper.setText(R.id.goods_detail_reputation_describe_tv,item.getGoodsEvaluationDetails().getGevalContent());
        helper.setText(R.id.shopkeeper_replies_tv,item.getGoodsEvaluationDetails().getGevalExplain());

        /**
         * 添加评论
         */
        addReputationImg(item.getResourceInfos());
    }

//    listImg
    private void addReputationImg(List<SelectAppRankBean.DataBean.ListBean.ResourceInfosBean> listImg) {
        if (reputationImgLayout.getChildCount()>0){
            reputationImgLayout.removeAllViews();
        }

        for (int i = 0; i < listImg.size(); i++) {

            View view = LayoutInflater.from(context).inflate(R.layout.item_compution_img_layout,null);

            LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
                    240, 240);
            lp.setMargins(0, 0, Tool.dip2px(context, 10), 10);
            view.setLayoutParams(lp);

            ImageView reputationIv = view.findViewById(R.id.reputation_img);

            Glide
                    .with(context)
                    .load(listImg.get(i).getUrlFrameCapture())
                    .transform(new Tool.GlideRoundTransform(context,15))
                    .placeholder(R.mipmap.classify_goods_default)
                    .error(R.mipmap.classify_goods_default)
                    .into(reputationIv);

            reputationImgLayout.addView(view);

        }
    }
}
